<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #ccc;
            color: #333;
            box-sizing: border-box;
        }

        ul,
        li {
            list-style: none;
        }

        .system {
            width: 60%;
            margin: 20px auto;
            background-color: #fff;
            text-align: center;
        }

        h1 {
            padding: 30px;
        }

        .type {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            width: 100%;
        }

        .item {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 33%;
            height: 50px;
        }



        button {
            width: 80px;
            height: 40px;
            margin: 30px 10px;
        }

        .current {
            background-color: pink;
            border-radius: 4%;
        }
    </style>
</head>

<body>
    <div class="system">
        <h1>郑坑抽饭系统</h1>
        <ul class="type">
            <li class="item">鱼香肉丝</li>
            <li class="item">烤肉拌饭</li>
            <li class="item">麻辣香锅</li>
            <li class="item">老碗面</li>
            <li class="item">黄焖鸡</li>
            <li class="item">羊肉烩面</li>
            <li class="item">麻辣烫</li>
            <li class="item">刀削面</li>
            <li class="item">胡辣汤</li>
        </ul>
        <button>开始</button>
    </div>


    <script>
        var lis = document.querySelectorAll('.item');
        var btn = document.querySelector('button');
        // console.log(lis);
        var flag = false;
        var timer = null;
        btn.addEventListener('click', function () {
            // console.log('点击')；
            if (flag) {
                clearInterval(timer);
                btn.innerHTML = '开始';
                flag = false;
            } else {
                timer = setInterval(function () {
                    // console.log(Math.floor(Math.random() * lis.length) + 1);
                    var num = Math.floor(Math.random() * lis.length);
                    for (let i = 0; i < lis.length; i++) {
                        lis[i].setAttribute('class', 'item');
                    }
                    return lis[num].className = 'item current';

                }, 10);
                // lis[num].setAttribute('class', 'item current');
                btn.innerHTML = '关闭';
                flag = true;
            }

        })


    </script>
</body>

</html>